<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>

<%@ page import="okhttp3.*" %>
<%@ page import="org.apache.http.conn.ssl.AllowAllHostnameVerifier" %>
<%--流程退回调用QMS接口--%>
<%

    try {
        JSONObject paramJson = new JSONObject();
        paramJson.put("appId", "FSAID_131e66a");
        paramJson.put("appSecret", "0f411325924942d0b3bf4d7d3f45a6ac");
        paramJson.put("permanentCode", "A76417A4210D210C88FE5F2C99BDD129");
        out.print(">>>>>测试接口>>>>>paramJson="+paramJson+"<br/>");
        OkHttpClient client = new OkHttpClient().newBuilder()
                .hostnameVerifier(new AllowAllHostnameVerifier())
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, paramJson.toJSONString());
        String url = "https://open.fxiaoke.com/cgi/corpAccessToken/get/V2";
        Request req = new Request.Builder()
                .url(url)
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        Response resp = client.newCall(req).execute();
        String result = resp.body().string();
        resp.body().close(); // 保证资源被释放
        // 增加对HTTP状态码的检查
        if (!resp.isSuccessful()) {
            out.print(">>>>>测试接口>>>>>response code :"+resp.code()+"<br/>");
        } else {
            if (!result.isEmpty()) {
                out.print(">>>>>测试接口>>>>>result:"+result+"<br/>");
            } else {
                out.print(">>>>>测试接口>>>>>response result is null<br/>");
            }
        }
    } catch (Exception e) {
        out.print(">>>>>测试接口>>>>>response timeout or network error:"+e+"<br/>");
    }

%>




